import main from "./openfaas_js/main.js"
import Todo from "./openfaas_js/utils/todo.js";
import GLOBAL from "./openfaas_js/GLOBAL.js";
import _function from "./openfaas_js/function/function.js"

const {AUTH_riscv64, AUTH_x86, AUTH_x86swarm, AUTH_x86qemu} = GLOBAL

const URL_PREFIX_riscv64 = `http://admin:${AUTH_riscv64.PASSWORD}@${AUTH_riscv64.HOST}:${AUTH_riscv64.PORT}/`
const URL_PREFIX_x86 = `http://admin:${AUTH_x86.PASSWORD}@${AUTH_x86.HOST}:${AUTH_x86.PORT}/`
const URL_PREFIX_x86swarm = `http://admin:${AUTH_x86swarm.PASSWORD}@${AUTH_x86swarm.HOST}:${AUTH_x86swarm.PORT}/`
const URL_PREFIX_x86qemu = `http://admin:${AUTH_x86qemu.PASSWORD}@${AUTH_x86qemu.HOST}:${AUTH_x86qemu.PORT}/`
const URL_PREFIX_list = [URL_PREFIX_riscv64, URL_PREFIX_x86qemu]
const FUNC_PREFIX_list = ["riscv64-", "x86-"]
const FUNC_NAME_list = _function.FUNCTION_LIST

async function syncExecute() {
    await Todo.showTodoList()
    // TankLab: 192.168.1.189
    try {
        let funcName_noPrefix = "python3-leastsquare"
        let loopCount = 10
        if (false) {
            // riscv64 192.168.10.2
            console.log("# RISC-V OpenFaaS faas-swarm")
            console.log("URL_PREFIX:", URL_PREFIX_riscv64, "\n-------")
            // await main.getAllFunctions(URL_PREFIX_riscv64);
            await main.invokeSingleFunction(URL_PREFIX_riscv64, `riscv64-${funcName_noPrefix}`, (await import(`./openfaas_js/function/${funcName_noPrefix}.js`)).default.paramsGenerator());
            // await main.loopInvokeSingleFunction(URL_PREFIX_riscv64, `riscv64-${funcName_noPrefix}`, loopCount);
            // -------
            // x86 10.30.245.207
            console.log("# X86 OpenFaaS faas-netes")
            console.log("URL_PREFIX:", URL_PREFIX_x86, "\n-------")
            // await main.getAllFunctions(URL_PREFIX_x86);
            await main.invokeSingleFunction(URL_PREFIX_x86, `x86-${funcName_noPrefix}`, (await import(`./openfaas_js/function/${funcName_noPrefix}.js`)).default.paramsGenerator());
            // await main.loopInvokeSingleFunction(URL_PREFIX_x86, `x86-${funcName_noPrefix}`, loopCount);
            // -------
            // x86swarm 10.30.245.163
            console.log("# X86 OpenFaaS faas-swarm")
            console.log("URL_PREFIX:", URL_PREFIX_x86swarm, "\n-------")
            // await main.getAllFunctions(URL_PREFIX_x86swarm);
            await main.invokeSingleFunction(URL_PREFIX_x86swarm, `swarm-x86-${funcName_noPrefix}`, (await import(`./openfaas_js/function/${funcName_noPrefix}.js`)).default.paramsGenerator());
        }
        if (true) {
            // await main.loopInvokeSingleSameFunctionUnderDifferentEnvs(URL_PREFIX_list, FUNC_PREFIX_list, funcName_noPrefix, loopCount)
            await main.loopInvokeMultiSameFunctionUnderDifferentEnvs(URL_PREFIX_list, FUNC_PREFIX_list, FUNC_NAME_list, loopCount)
        }
    } catch (error) {
        console.error("An error occurred:", error);
    }
}

syncExecute().then(r => {
})

